package com.zjp;

import com.google.common.base.Throwables;
import org.junit.jupiter.api.Test;

import java.sql.SQLException;

public class ThrowableTest {

    @SuppressWarnings("RedundantThrows")
    @Test
    public void t1() throws SQLException {
        try {
            errMethod();
        } catch (Throwable t) {
            // 如果是相同类型的就throw
            Throwables.throwIfInstanceOf(t, NullPointerException.class);
        }

        System.out.println("TEST");
    }

    public void errMethod() throws SQLException {
        sqlMethod();
        String str = null;
        System.out.println(str.length());
    }

    public void sqlMethod() throws SQLException {
        if (true) {
            throw new SQLException("SQL");
        }
    }
}
